package com.mz.demo.utils.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.Map;

@Data
public class R {
    private Integer code;
    private String msg;
    private Object data;

    public static  R ok(){
        return ok(null);
    }

    public static R ok( Object data ){
        R res = new R();
        res.code = 200;
        res.msg = "true";
        res.data = data;
        return res;
    }

    public static R ok(  PaginationVo paginationVo,  IPage page ){

        PaginationRes paginationRes = new PaginationRes();
        paginationRes.setPageIndex(paginationVo.getPageIndex());
        paginationRes.setPageSize(paginationVo.getPageSize());
        paginationRes.setTotal(page.getTotal());
        paginationRes.setList(page.getRecords());

        return R.ok(paginationRes);
    }

    public static R fail( String msg ){
        return fail(-1, msg);
    }


    public static R fail( Integer code, String msg ){
        return fail(code, msg, null);
    }

    public static R fail( Integer code, String msg, Object data ){
        R res = new R();
        res.code = code;
        res.msg = msg;
        res.data = data;
        return res;
    }

}
